package com.bum.api.processor.dj.html.bo;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.math.NumberUtils;

import com.bum.api.bo.DjGuruBO;
import com.bum.api.core.exp.om.Metas;
import com.bum.api.core.exp.om.Params;
import com.bum.api.core.html.HtmlModel;
import com.bum.api.core.html.HtmlRender;
import com.bum.guru.exp.dj.om.Song;

public class DjHtmlViewBO {
	HtmlRender	htmlRender;
	DjGuruBO	djGuruBO;

	private int	maxResults	= 20;

	public String home(String path, Params params, Metas metas) {
		HtmlModel model = HtmlModel.get(metas);

		List<Song> songs = djGuruBO.listSongs(0, 0, maxResults);
		model.put("songs", songs);
		if (CollectionUtils.isNotEmpty(songs)) {
			model.put("moreUrl", "/app/dj/songs/" + songs.get(songs.size() - 1).getId());
		}

		return htmlRender.render("dj/dj-home", model);
	}

	public String songs(String path, Params params, Metas metas) {
		HtmlModel model = HtmlModel.get(metas);

		long fromId = NumberUtils.toLong(path, 0);
		List<Song> songs = djGuruBO.listSongs(0, fromId, maxResults);
		model.put("songs", songs);
		if (CollectionUtils.isNotEmpty(songs)) {
			model.put("moreUrl", "/app/dj/songs/" + songs.get(songs.size() - 1).getId());
		}

		return htmlRender.render("dj/dj-songs", model);
	}

	public String top(String path, Params params, Metas metas) {
		HtmlModel model = HtmlModel.get(metas);

		int viewId = NumberUtils.toInt(path, 0);
		List<Song> songs = djGuruBO.listTop(viewId);
		model.put("songs", songs);
		
		model.put("title", "1".equals(path) ? "Nonstop HOT" : "Nonstop tuyển chọn");

		return htmlRender.render("dj/dj-top", model);
	}

	public String song(String path, Params params, Metas metas) {
		HtmlModel model = HtmlModel.get(metas);

		long id = NumberUtils.toLong(path, 0);
		Song song = djGuruBO.get(id);
		model.put("song", song);

		return htmlRender.render("dj/dj-song", model);
	}

	public void setDjGuruBO(DjGuruBO djGuruBO) {
		this.djGuruBO = djGuruBO;
	}

	public void setHtmlRender(HtmlRender htmlRender) {
		this.htmlRender = htmlRender;
	}
}
